<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Admin extends CI_Controller {


    private $data ;
    function __construct() {
        parent::__construct();
        $this->data['tb_is_login'] = $this->session->userdata('tb_is_login');
        $this->data['tb_nick'] = $this->session->userdata('tb_nick');
    }

    /**
     *
     * 登陆页面
     */
    function login(){
        //是否已经登陆
        $admin_user_id = $this->session->userdata('admin_user_id');
        if(!empty($admin_user_id))redirect(site_url('admin/index'));
        $data['login_url'] = site_url('admin/index/tologin');
        $data['sitelogo'] = $GLOBALS['config']['sitelogo'];
        $this->load->view('index/login',$data);
    }

    /**
     *
     * 登陆处理操作
     */
    function tologin(){
        $arg_post = $this->input->post();

        //验证码验证
        $this->load->library('mycaptchaclass');
        if(!$this->mycaptchaclass->check($arg_post['code'])){
            $this->error('验证码不正确，请重新输入！',site_url('admin/index/login'),'1');
        }

        if(empty($arg_post['username'])||empty($arg_post['password'])){
            $this->error('用户名或者密码不能为空，请重新输入！',site_url('admin/index/login'),'1');
        }
        $this->load->model('admin.Adminuser_model');
        if($this->Adminuser_model->login($arg_post['username'],$arg_post['password'])){
            redirect(site_url('admin/index'));
        }else{
            $this->error("用户名或者密码错误，登陆失败！",site_url('admin/index/login'),1);
        }
    }

    /**
     *
     * 登录退出
     */
    function logout(){


    }

    /**
     * 后台首页
     */
    public function custom_index()
    {
        $data = array();
        $this->load->view('admin/index/main', $data);
    }

    function index(){

        $is_login = $this->session->userdata('tb_is_login');
        if(!$is_login)  redirect(site_url('oauth/tb_oauth'));

        //获得左侧菜单列表
        include_once(LIBPATH.'/Menu.php');
        $this->data['left_menu'] = $left_menu;
        $this->load->view('admin/frame',$this->data);
    }


    public function page_header(){
        $this->load->view('public/page_header');
    }




}